from flask import Flask, render_template, request
from apps.controller.UserController import user_bp
from apps.pojo.Entitiy import db
from apps.service.LoginService import LoginService
app = Flask(__name__)
# 注册蓝图对象
app.register_blueprint(user_bp)
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+pymysql://root:hy030812@{ipaddress}:{port}/{database}".format( ipaddress="localhost",port="3306",database="flask")

with app.app_context():
    db.init_app(app)
    # db.drop_all()
    # db.create_all()
# class PhoneConverter(BaseConverter):
#     regex = r'1[34578]\d{9}'
# app.url_map.converters['phone'] = PhoneConverter
#
# @app.route('/phone/<phone:phone>',methods=['GET'])
# def phone(phone):
#     return f'phone:{phone}'
#
# # #方式一
# # app.config['TEMPLATES_AUTO_RELOAD'] = True
# # app.config['SECRET_KEY'] = '123@qee'
# # app.config['SQL_DEBUG'] =''
# # #方式二
# # app.config.update(
# #     TEMPLATES_AUTO_RELOAD=True,
# #     SECRET_KEY='123@qee',
# #     SQL_DEBUG=''
# # )
# # #方式三
# # app.config.from_file('config.json',load=json.load)
@app.route('/')
def tologin():
    return render_template('login.html')
@app.route('/login',methods=['POST'])
def dologin():
    param = request.form
    username = param.get('username')
    password = param.get('password')
    #调用登陆方法
    user = LoginService.login(username,password)
    if user:
        return render_template('index.html',user=user)
    else:
        return render_template('login.html')

# @app.route('/index_resp')
# def index_resp(): # put application's code here
#     resp = Response(response='Python&Flask',status=201,mimetype='text/plain')
#     return resp
# @app.route('/dept/list')
# def dept_index(): # put application's code here
#     name = 'hello'
#     return render_template("index.html",name=name)
# @app.route('/hello/<num>')
# def hello(num):
#     return 'hello ' + num
@app.route('/index_v1')
def index_v1(): # put application's code here
    return render_template('index_v1.html')
@app.route('/index_v3')
def index_v3():
    return render_template('index_v3.html')
if __name__ == '__main__':
    app.run()
